package com.spring.sso.common;

import lombok.Data;

/**
 * @author : pangfuzhong
 * @description
 * @date : 2021/9/16 11:19
 */
@Data
public class CommonResult<T> {

    private Integer code;

    private String message;

    private T data;

    public CommonResult() {

    }

    public CommonResult(T data) {
        this.code = 200;
        this.message = "请求成功";
        this.data = data;
    }

    public static CommonResult success(Object data) {
        return new CommonResult(data);
    }

    public static CommonResult success(String message, Object data) {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(200);
        commonResult.setMessage(message);
        commonResult.setData(data);
        return commonResult;
    }

    public static CommonResult failed() {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(400);
        commonResult.setMessage("token生成失败");
        commonResult.setData(null);
        return commonResult;
    }

    public static CommonResult failed(int i, String s) {
        CommonResult commonResult = new CommonResult();
        commonResult.setData(null);
        commonResult.setCode(i);
        commonResult.setMessage(s);
        return commonResult;
    }
}
